/* ;(function($){
    $.fn.extend({
        hjDrag(titleSelector){
            // 有title只能拖title，没有就拖整个this
            const ele=titleSelector?this.find(titleSelector):this
            this.css("position","absolute")
            ele.on("mousedown",e=>{
                let disX=e.offsetX,
                    disY=e.offsetY
                $(document).on("mousemove",e=>{
                    this.css({
                        left:e.clientX-disX,
                        top:e.clientY-disY
                    })
                })
                $(document).on("mouseup",function(){
                    $(this).off("mousemove")
                })
                e.preventDefault()
            })
        }
    })
})(jQuery) */


;(function($){
    $.fn.extend({
        hjDrag(option){
            // 有title只能拖title，没有就拖整个this
            console.log(option)
            const ele=option.titleSelector?this.find(option.titleSelector):this
            this.css("position","absolute")
            ele.on("mousedown",e=>{
                let disX=e.offsetX,
                    disY=e.offsetY
                $(document).on("mousemove",e=>{
                    let _left=e.clientX-disX,
                        _top=e.clientY-disY
                    if(_left<option.left){
                        _left=option.left
                    }
                    else if(_left>option.right){
                        _left=option.right
                    }
                    if(_top<option.up){
                        _top=option.up
                    }
                    else if(_top>option.down){
                        _top=option.down
                    }
                    this.css({
                        left:_left,
                        top:_top
                    })
                })
                $(document).on("mouseup",function(){
                    $(this).off("mousemove")
                })
                e.preventDefault()
            })
        }
    })
})(jQuery)